/**
 * @param {number} k
 */
var MyCircularQueue = function(k) {
  this.queue = [];
  this.length = k;
  this.start = -1;
  this.end = -1;
};

/**
 * @param {number} value
 * @return {boolean}
 */
MyCircularQueue.prototype.enQueue = function(value) {
  if(this.isFull()) {
    return false;
  } else {
    if(this.start == -1) {
      this.start = 0;
      this.end = 0;
      this.queue[this.start] = value;
    } else {
      this.end = (this.end + 1) % this.length;
      this.queue[this.end] = value;
    }
    return true;
  }
};

/**
 * @return {boolean}
 */
MyCircularQueue.prototype.deQueue = function() {
  if(this.isEmpty()) {
    return false;
  } else {
    // 只有一个元素了
    if(this.start == this.end) {
      this.start = -1;
      this.end = -1;
    } else {
      this.start = (this.start + 1) % this.length;
    }
    return true;
  }
};

/**
 * @return {number}
 */
MyCircularQueue.prototype.Front = function() {
  console.log("Front", this.start);
  if(this.isEmpty()) {
    return -1;
  } else {
    return this.queue[this.start];
  }
};

/**
 * @return {number}
 */
MyCircularQueue.prototype.Rear = function() {
  if(this.isEmpty()) {
    return -1;
  } else {
    return this.queue[this.end];
  }
};

/**
 * @return {boolean}
 */
MyCircularQueue.prototype.isEmpty = function() {
  return this.start == -1;
};

/**
 * @return {boolean}
 */
MyCircularQueue.prototype.isFull = function() {
  // console.log("是否为满", this.start, this.end, this.length, this.queue, (this.end + 1) % this.length == this.start);
  return this.start != -1 && (this.end + 1) % this.length == this.start;
};

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * var obj = new MyCircularQueue(k)
 * var param_1 = obj.enQueue(value)
 * var param_2 = obj.deQueue()
 * var param_3 = obj.Front()
 * var param_4 = obj.Rear()
 * var param_5 = obj.isEmpty()
 * var param_6 = obj.isFull()
 */
let options = [
  ["MyCircularQueue","enQueue","enQueue","enQueue","enQueue","Rear","isFull","deQueue","enQueue","Rear"],
  [[3],[1],[2],[3],[4],[],[],[],[4],[]]
];
options = [
  ["MyCircularQueue","enQueue","enQueue","deQueue","enQueue","deQueue","enQueue","deQueue","enQueue","deQueue", "Front"],
  [[2],[1],[2],[],[3],[],[3],[],[3],[],[]]
];
var obj = new MyCircularQueue(options[1][0][0]), result = [];
for(let i = 1; i < options[0].length; i++) {
  // console.log(obj.queue);
  let res = obj[options[0][i]](options[1][i][0]);
  result.push(res);
}
console.log(result);
